// 膳食管理 / 供应商管理

import r from '@/utils/request';
import type { ListParams, ListResponseType ,ResponseType} from '../types';


enum API {
    list = '/supplier/list', //供应商列表
    del = '/supplier/delete/', //删除供应商
    add = '/supplier/add', //添加供应商
    supplierget = '/supplier/get/', //根据id获取供应商
    update = '/supplier/update',//修改供应商
    delAll = '/supplier/deleteAll'//批量删除
}

export interface supplierItem {
  id: number;
}


type GetsupplierlistResType = ListResponseType<{
    id: number,
    companyId: number,
    name: string,
    linkMan: string,
    mobile: string,
    foodCounts: number
}>


export interface SupplierAddRes {
    code: number;
    msg:  string;
    data: SupplierAddData;
}

export interface SupplierAddData {
    id:         number;
    companyId:  number;
    name:       string;
    linkMan:    any;
    mobile:     string;
    foodCounts: number;
}

export interface SupplierAddParam{
    id: number,
    name:string,
    linkMan: string,
    mobile: string
}

export function DelSupplierAPI(id: number): Promise<ResponseType<null>> {
    return r.delete(API.del  + id);
}
export function getSupplierlistAPI(params: ListParams): Promise<GetsupplierlistResType> {
    return r.get(API.list, params);
}
export function SuppliergetAPI(id:number): Promise<ResponseType<null>> {
    return r.get(API.list+id);
}
export function SupplierAddAPI(data: SupplierAddParam): Promise<SupplierAddRes> {
    return r.post(API.add, data);
}
export function SupplierUpdateAPI(data: SupplierAddParam): Promise<SupplierAddRes> {
    return r.put(API.update, data);
}
export function DelAllSupplierAPI(id: number[]): Promise<ResponseType<null>> {
    return r.post(API.delAll, id);
}